const express = require("express");
const router = express.Router();
const {
  add,
  del,
  update,
  allList,
  detail,
  getStoreNum,
  getMaxOutNumber,
} = require("../public/javascripts/outBound");
const db = require("../db");

router.post("/add", (req, res) => {
  const unitInfo = req.body;
  // 执行定义好的登录函数
  add(req, res);
});

router.delete("/delete", (req, res) => {
  const unitInfo = req.body;
  //对客户端的数据进行校验
  if (unitInfo.id === "") {
    return res.send({
      success: false,
      message: "编码不能为空",
    });
  }
  // 执行定义好的登录函数
  del(req, res);
});

router.put("/update", (req, res) => {
  const unitInfo = req.body;
  //对客户端的数据进行校验
  if (unitInfo.id === "") {
    return res.send({
      success: false,
      message: "编码不能为空",
    });
  }
  // 执行定义好的登录函数
  update(req, res);
});

router.post("/list", (req, res) => {
  // 执行定义好的登录函数
  allList(req, res);
});

router.post("/detail", (req, res) => {
  // 执行定义好的登录函数
  detail(req, res);
});

router.post("/getStoreNum", (req, res) => {
  // 执行定义好的登录函数
  getStoreNum(req, res);
});

router.post("/getMaxOutNumber", (req, res) => {
  const unitInfo = req.body;
  if (unitInfo.dateTime === "") {
    return res.send({
      success: false,
      message: "日期不能为空",
    });
  }
  if (unitInfo.warehouseId === "") {
    return res.send({
      success: false,
      message: "仓库不能为空",
    });
  }
  getMaxOutNumber(req, res);
});

module.exports = router;
